home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 125 / Computer Shopper CD-ROM Issue 125 (1998-07)(Dennis Publishing).iso / Business / Dazzler / DAZZLER.Z / CPushButtonResponse.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-11-26  |  6.1 KB  |  299 lines

  1. import java.awt.Color;
  2. import java.awt.Dimension;
  3. import java.awt.Graphics;
  4. import java.awt.Point;
  5. import java.awt.Rectangle;
  6. import java.awt.image.ImageObserver;
  7. import java.io.DataInputStream;
  8.  
  9. public class CPushButtonResponse extends CDisplayResponse {
  10.    final short IN_REGION = 256;
  11.    final short CUSTOM_BTN = 512;
  12.    static final byte image_on_button = 0;
  13.    static final byte up_image = 1;
  14.    static final byte down_image = 2;
  15.    static final byte over_image = 3;
  16.    static final byte image_count = 4;
  17.    protected CFontObject m_clsFontObject = new CFontObject();
  18.    protected int m_nFlags = 16;
  19.    protected char m_cPrefixChar = 0;
  20.    protected String m_strTitle = "Continue";
  21.    protected String m_strImageOnButton = "";
  22.    protected String m_strUpImage = "";
  23.    protected String m_strDownImage = "";
  24.    protected String m_strOverImage = "";
  25.    protected String m_strCursorName = "";
  26.    protected Color m_rgbText = null;
  27.    protected Color m_rgbFace;
  28.    protected Color m_rgbShadow;
  29.    protected Color m_rgbHighlight;
  30.    protected Color m_rgbTrans;
  31.    protected short m_cBorderWidth;
  32.    protected CPicture[] m_Image;
  33.    private String m_strNewTitle;
  34.    private int m_wState;
  35.  
  36.    void DrawCustomButton(Graphics var1, CRect var2) {
  37.       if (Utils.StateTest(this.m_wState, 256)) {
  38.          if (Utils.StateTest(this.m_wState, 8)) {
  39.             this.m_Image[2].Draw(var1, var2);
  40.          } else {
  41.             this.m_Image[3].Draw(var1, var2);
  42.          }
  43.       } else {
  44.          this.m_Image[1].Draw(var1, var2);
  45.       }
  46.    }
  47.  
  48.    boolean LoadFromFile(DataInputStream var1) {
  49.       this.m_strTitle = FileLoad.ReadCString(var1);
  50.       this.m_cPrefixChar = (char)FileLoad.ReadCPlusByte(var1);
  51.       this.m_nFlags = FileLoad.ReadCPlusInt(var1);
  52.       this.m_rgbText = FileLoad.ReadColor(var1);
  53.       this.m_rgbFace = FileLoad.ReadColor(var1);
  54.       this.m_rgbShadow = FileLoad.ReadColor(var1);
  55.       this.m_rgbHighlight = FileLoad.ReadColor(var1);
  56.       this.m_cBorderWidth = FileLoad.ReadCPlusByte(var1);
  57.       if (Globals.CUR_COURSE.m_nFileVersion > 3) {
  58.          this.m_strCursorName = FileLoad.ReadCString(var1);
  59.       }
  60.  
  61.       int var2 = 0;
  62.  
  63.       do {
  64.          this.m_Image[var2].LoadFromFile(var1);
  65.          ++var2;
  66.       } while(var2 < 4);
  67.  
  68.       this.m_clsFontObject.LoadFromFile(var1);
  69.       return super.LoadFromFile(var1);
  70.    }
  71.  
  72.    void Draw3DButton(Graphics var1, CRect var2) {
  73.       Graphics var3 = var1.create();
  74.       CRect var4 = new CRect(var2);
  75.       ((Rectangle)var4).grow(-this.m_cBorderWidth - 1, -this.m_cBorderWidth - 1);
  76.       if ((this.m_nFlags & 16) != 0) {
  77.          var3.setColor(Color.black);
  78.          var3.drawRoundRect(var2.x, var2.y, var2.width - 1, var2.height - 1, 2, 2);
  79.       }
  80.  
  81.       var3.setColor(this.m_rgbFace);
  82.       var3.fillRect(var4.x, var4.y, var4.width, var4.height);
  83.       if (Utils.StateTest(this.m_wState, 8) && Utils.StateTest(this.m_wState, 256)) {
  84.          for(int var6 = 0; var6 < this.m_cBorderWidth; ++var6) {
  85.             var3.setColor(this.m_rgbShadow);
  86.             var3.drawLine(var2.x + 1, var2.y + var6 + 1, var2.x + var2.width - 2 - var6, var2.y + var6 + 1);
  87.             var3.drawLine(var2.x + var6 + 1, var2.y + 1, var2.x + var6 + 1, var2.y + var2.height - 3 - var6);
  88.             var3.setColor(this.m_rgbHighlight);
  89.             var3.drawLine(var2.x + 1 + var6, var2.y + var2.height - 2 - var6, var2.x + var2.width - 2, var2.y + var2.height - 2 - var6);
  90.             var3.drawLine(var2.x + var2.width - 2 - var6, var2.y + 2 + var6, var2.x + var2.width - 2 - var6, var2.y + var2.height - 2);
  91.          }
  92.  
  93.          int var7 = Math.min(this.m_cBorderWidth, 3);
  94.          var4.x += var7;
  95.          var4.y += var7;
  96.          var4.width -= var7;
  97.          var4.height -= var7;
  98.       } else {
  99.          for(int var5 = 0; var5 < this.m_cBorderWidth; ++var5) {
  100.             var3.setColor(this.m_rgbHighlight);
  101.             var3.drawLine(var2.x + 1, var2.y + var5 + 1, var2.x + var2.width - 2 - var5, var2.y + var5 + 1);
  102.             var3.drawLine(var2.x + var5 + 1, var2.y + 1, var2.x + var5 + 1, var2.y + var2.height - 3 - var5);
  103.             var3.setColor(this.m_rgbShadow);
  104.             var3.drawLine(var2.x + 1 + var5, var2.y + var2.height - 2 - var5, var2.x + var2.width - 2, var2.y + var2.height - 2 - var5);
  105.             var3.drawLine(var2.x + var2.width - 2 - var5, var2.y + 2 + var5, var2.x + var2.width - 2 - var5, var2.y + var2.height - 2);
  106.          }
  107.       }
  108.  
  109.       if (this.m_Image[0].m_strFilename.length() == 0) {
  110.          var3.setColor(this.m_rgbText);
  111.          var3.setFont(this.m_clsFontObject.GetFont());
  112.          int var8 = Math.min(var4.height, Utils.DrawText(var3, this.m_strNewTitle, var4, 34).height);
  113.          var4.y += (var4.height - var8) / 2;
  114.          var4.height = var8;
  115.          Utils.DrawText(var3, this.m_strNewTitle, var4, 2);
  116.       } else {
  117.          if (this.m_Image[0].m_Image != null) {
  118.             if (this.m_Image[0].m_Image.getWidth((ImageObserver)null) < var4.width) {
  119.                var4.x += (var4.width - this.m_Image[0].m_Image.getWidth((ImageObserver)null)) / 2;
  120.             }
  121.  
  122.             if (this.m_Image[0].m_Image.getHeight((ImageObserver)null) < var4.height) {
  123.                var4.y += (var4.height - this.m_Image[0].m_Image.getHeight((ImageObserver)null)) / 2;
  124.             }
  125.          }
  126.  
  127.          this.m_Image[0].Draw(var3, var4);
  128.       }
  129.    }
  130.  
  131.    boolean ProcessMouseUp(Point var1) {
  132.       boolean var2 = false;
  133.       if (Utils.StateTest(this.m_wState, 8)) {
  134.          this.m_wState = Utils.StateClear(this.m_wState, 8);
  135.          Globals.thePresView.Render(((CDisplayResponse)this).GetDrawRect());
  136.          Globals.thePresView.Draw((Graphics)null, ((CDisplayResponse)this).GetDrawRect());
  137.          var2 = true;
  138.       }
  139.  
  140.       return var2;
  141.    }
  142.  
  143.    boolean OnKeyPress(int var1, int var2) {
  144.       boolean var3 = false;
  145.       if (this.m_cPrefixChar > 0 && var1 == Character.toUpperCase(this.m_cPrefixChar)) {
  146.          var3 = true;
  147.       }
  148.  
  149.       return var3;
  150.    }
  151.  
  152.    public CPushButtonResponse() {
  153.       super(23);
  154.       this.m_rgbFace = Color.lightGray;
  155.       this.m_rgbShadow = Color.darkGray;
  156.       this.m_rgbHighlight = Color.white;
  157.       this.m_rgbTrans = null;
  158.       this.m_cBorderWidth = 2;
  159.       this.m_strNewTitle = "";
  160.       this.m_wState = 0;
  161.       this.m_Image = new CPicture[4];
  162.  
  163.       for(int var1 = 0; var1 < this.m_Image.length; ++var1) {
  164.          this.m_Image[var1] = new CPicture();
  165.       }
  166.  
  167.    }
  168.  
  169.    CResponseReturn DoResponse(int var1) {
  170.       return super.DoResponse(var1);
  171.    }
  172.  
  173.    boolean OnMouseClick(int var1, int var2, Point var3, int var4, CRect var5) {
  174.       boolean var6 = false;
  175.       if (var4 == 7) {
  176.          if (var1 == 2022 && ((CDisplayResponse)this).HitTest(var3)) {
  177.             var6 = this.ProcessMouseDown(var3);
  178.          } else if (var1 == 2023) {
  179.             if (((CDisplayResponse)this).HitTest(var3)) {
  180.                var6 = this.ProcessMouseUp(var3);
  181.             } else if (Utils.StateTest(this.m_wState, 8)) {
  182.                this.m_wState = Utils.StateClear(this.m_wState, 8);
  183.             }
  184.          }
  185.       }
  186.  
  187.       return var6;
  188.    }
  189.  
  190.    boolean SetResponse() {
  191.       boolean var1 = false;
  192.       String var2 = Utils.InsertVariablesInString(this.m_strTitle);
  193.       if (!this.m_strNewTitle.equals(var2)) {
  194.          this.m_strNewTitle = var2;
  195.          var1 = true;
  196.       }
  197.  
  198.       CRect var3 = new CRect(((CDisplayResponse)this).GetActualRect());
  199.       if (this.m_Image[1].m_strFilename.length() <= 0 && this.m_Image[2].m_strFilename.length() <= 0 && this.m_Image[3].m_strFilename.length() <= 0) {
  200.          if (this.m_Image[0].m_strFilename.length() > 0) {
  201.             if (!this.m_Image[0].HasImageLoaded()) {
  202.                var1 = true;
  203.             }
  204.  
  205.             this.m_Image[0].LoadImage();
  206.          }
  207.       } else {
  208.          Dimension var5 = new Dimension();
  209.          if (!this.m_Image[1].HasImageLoaded()) {
  210.             var1 = true;
  211.          }
  212.  
  213.          int var6 = 1;
  214.  
  215.          do {
  216.             Dimension var4;
  217.             if ((var4 = this.m_Image[var6].LoadImage()) != null) {
  218.                var5.width = Math.max(var5.width, var4.width);
  219.                var5.height = Math.max(var5.height, var4.height);
  220.             }
  221.  
  222.             ++var6;
  223.          } while(var6 < 4);
  224.  
  225.          ((Rectangle)var3).resize(Math.min(var3.width, var5.width), Math.min(var3.height, var5.height));
  226.          this.m_wState = Utils.StateSet(this.m_wState, 512);
  227.       }
  228.  
  229.       if (!((Rectangle)var3).equals(((CDisplayResponse)this).GetDrawRect())) {
  230.          if (!((CDisplayResponse)this).GetDrawRect().isEmpty()) {
  231.             Globals.thePresView.InvalidateOffScreenRect(((CDisplayResponse)this).GetDrawRect());
  232.          }
  233.  
  234.          ((CDisplayResponse)this).SetDrawRect(var3);
  235.          var1 = true;
  236.       }
  237.  
  238.       Globals.thePresView.AddDrawObject((CIconObject)this, 1024, var1);
  239.       return true;
  240.    }
  241.  
  242.    boolean ProcessMouseDown(Point var1) {
  243.       if (!Utils.StateTest(this.m_wState, 8)) {
  244.          this.m_wState = Utils.StateSet(this.m_wState, 8);
  245.          Globals.thePresView.Render(((CDisplayResponse)this).GetDrawRect());
  246.          Globals.thePresView.Draw((Graphics)null, ((CDisplayResponse)this).GetDrawRect());
  247.       }
  248.  
  249.       return false;
  250.    }
  251.  
  252.    boolean OnMouseMove(int var1, Point var2, int var3, CRect var4) {
  253.       if (var3 == 7) {
  254.          CRect var5 = new CRect();
  255.          if (var4 != null) {
  256.             var5.reshape(var4);
  257.          } else {
  258.             var5.reshape(((CDisplayResponse)this).GetActualRect());
  259.          }
  260.  
  261.          if (((CDisplayResponse)this).HitTest(var2)) {
  262.             if (!Utils.StateTest(this.m_wState, 256)) {
  263.                this.m_wState = Utils.StateSet(this.m_wState, 256);
  264.                if (Utils.StateTest(this.m_wState, 512) || Utils.StateTest(this.m_wState, 8)) {
  265.                   Globals.thePresView.Render(var5);
  266.                   Globals.thePresView.Draw((Graphics)null, var5);
  267.                }
  268.  
  269.                if ((((CResponse)this).GetResponseFlags() & 32) == 0 && super.m_ActionManager.GetIconList().size() > 0) {
  270.                   super.m_ActionManager.OnDoAction();
  271.                   Globals.thePresView.RenderAndDrawDirtyList();
  272.                }
  273.             }
  274.          } else if (Utils.StateTest(this.m_wState, 256)) {
  275.             this.m_wState = Utils.StateClear(this.m_wState, 256);
  276.             if (Utils.StateTest(this.m_wState, 512) || Utils.StateTest(this.m_wState, 8)) {
  277.                Globals.thePresView.Render(var5);
  278.                Globals.thePresView.Draw((Graphics)null, var5);
  279.             }
  280.  
  281.             if ((((CResponse)this).GetResponseFlags() & 32) == 0 && super.m_ActionManager.GetIconList().size() > 0) {
  282.                super.m_ActionManager.RemoveDrawObjects();
  283.                Globals.thePresView.RenderAndDrawDirtyList();
  284.             }
  285.          }
  286.       }
  287.  
  288.       return false;
  289.    }
  290.  
  291.    void DrawObject(Graphics var1, int var2, CRect var3) {
  292.       if (Utils.StateTest(this.m_wState, 512)) {
  293.          this.DrawCustomButton(var1, var3);
  294.       } else {
  295.          this.Draw3DButton(var1, var3);
  296.       }
  297.    }
  298. }
  299.